package com.wen.service;

import com.wen.client.MemcacheCache;
import com.wen.manager.MemcacheCacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * Created by teddy on 2017/3/30.
 */
@Service
public abstract class CacheBaseService<T> implements ICacheBaseService<T> {

    @Autowired
    private MemcacheCacheManager cacheManager;

    @Override
    @CachePut(value = "systemCache")
    public T get(Serializable id) {
        Cache a = cacheManager.getCache("a");
        a.put("asdf", "asdf");

        a = cacheManager.getCache("a");
        System.out.println(a.get("asdf"));
        return null;
    }

    @Override
    @CacheEvict(value = "systemCache", allEntries = true, beforeInvocation = true)
    public void save(T[] entity) {

//        super.save(entity);
    }

    @Override
    @CacheEvict(value = "systemCache", allEntries = true, beforeInvocation = true)
    public void save(T entity) {
//        super.save(entity);
    }

    @Override
    @CacheEvict(value = "systemCache", allEntries = true, beforeInvocation = true)
    public Serializable saveObj(T entity) {
//        return super.saveObj(entity);
        return null;
    }

    @Override
    @CacheEvict(value = "systemCache", allEntries = true, beforeInvocation = true)
    public void update(T entity) {
//        super.update(entity);
    }

    @Override
    @CacheEvict(value = "systemCache", allEntries = true, beforeInvocation = true)
    public void delete(T entity) {
//        super.delete(entity);
    }

    @Override
    @CacheEvict(value = "systemCache", beforeInvocation = true)
    public int delete(Serializable id) {
//        return super.delete(id);
        return 0;
    }

    @Override
    @CacheEvict(value = "systemCache", allEntries = true, beforeInvocation = true)
    public void delete(Serializable... id) {
//        super.delete(id);
    }
}
